# Maintainer: Alexey Slokva <Alesha72003@ya.ru>

_realname=volk
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.5.0
pkgrel=1
pkgdesc="vector optimized runtime tools
 Vector-Optimized Library of Kernels is designed to help
 applications work with the processor's SIMD instruction sets. These are
 very powerful vector operations that can give signal processing a
 huge boost in performance.
 .
 This package includes the volk_profile tool. (mingw-w64)"
arch=('any')
url='https://github.com/gnuradio/volk'
license=('GPL3')
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-orc"
         "${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-python3-mako"
         "${MINGW_PACKAGE_PREFIX}-python3-six")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             'patch')
source=("https://github.com/gnuradio/volk/releases/download/v2.5.0/volk-2.5.0.tar.gz"{,.asc}
        '001-disable-failed-test.patch')
sha256sums=('d9183b9f86a32cdbb8698cbbeb15de574962c05200ccf445c1058629073521f8'
            'SKIP'
            '050d1780dfbeeeee93a72449ff6be5216b84a53dde70e704a19a99c66a741f30')
validpgpkeys=('60FD9F5FDCDC9C8CE87BA5150579D69772CD9B22') # Johannes Demel <jdemel@gnuradio.org>

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -Np1 -i "${srcdir}"/001-disable-failed-test.patch
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python3 \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${extra_config[@]}" \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

check() {
  cd "${srcdir}"/build-${CARCH}

  ${MINGW_PREFIX}/bin/cmake --build . --target test
}
package() {
  cd "${srcdir}"/build-${CARCH}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
